  class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }
  }
public class bibtwork1 {
   //力扣： 572. 另一棵树的子树
    public boolean isSubtree(TreeNode root, TreeNode subRoot) {
        if(root==null){
            return false;
        }
        //if(root==subRoot){
        //   return true;
        //}
        //这里的判断可以直接放到isBathme中
        //    if((root!=null&&subRoot==null)||(root==null&&subRoot!=null)){
        //         return false;
        //     }
        //     boolean ret1=false;
        //     boolean ret2=false;
        //     boolean ret3=false;
        //      ret1=isBathme(root.left,subRoot);
        //      ret2=isBathme(root.right,subRoot);
        //      ret3=isBathme(root,subRoot);
        //     if(ret1==true||ret2==true||ret3){
        //         return true;
        //     }
        if(isBathme(root,subRoot)){
            return true;
        }
        return isSubtree(root.left,subRoot)||isSubtree(root.right,subRoot);
    }
    public boolean isBathme(TreeNode first,TreeNode scend){
        if(first==null&&scend==null){
            return true;
        }
        if((first!=null&&scend==null)||(first==null&&scend!=null)){
            return false;
        }
        if(first.val!=scend.val){
            return false;
        }
        return isBathme(first.left,scend.left)&&isBathme(first.right,scend.right);
    }
}
